<!--
  - Copyright (c) 2018.
  - 北京九思金信科技有限公司对该文件内容保留所有权利。
  - 未经许可，不得私自拷贝、传播、发布、引用该文件内容，违者将被追究法律责任。
  -->

<template>
  <el-row class="joys-admin-header">
    <el-col :span="8">
      <div class="joys-admin-header__left-bar">
        <div class="menuImg_box_top" @mouseenter="menuEventHide"></div>
        <div class="menuImg_box" @mouseenter="menuEvent">
          <!--<img class="joys-menu-img" src="../../assets/sue.png" alt=""/>-->
          <i class="el-icon-menu joys-menu-img"></i>
          <span class="joys-navigation-text">导航</span>
          <div style="margin-left: 24px;width: 1px;height: 24px;border-radius: 8px;background: #E1E4EF;"></div>
        </div>
        <div class="menuImg_box_right"  @mouseenter="menuEventHide"></div>
      </div>
    </el-col>

    <el-col :span="8">
      <img :src="this.logo" style="width: 160px;height: 28.1px;margin-top: 10px;"/>
    </el-col>
    <el-col :span="8">
      <div class="joys-admin-header__right-bar" @mouseenter="menuEventHide">
        <el-popover placement="bottom" trigger="hover">
        <span slot="reference">
          <i class="joys-icon-notice"/>
        </span>
          <div>
            <!-- <span>共有{{num}}条未读消息</span>
            <el-button type="text" @click="message">查看全部...</el-button>-->
          </div>
        </el-popover>
        <el-dropdown @command="onUserCommand" placement="bottom">
        <span class="joys-admin-header__user">
          <span class="joys-admin-header__user-text">{{ user.userName }}</span>
          <img class="joys-admin-header__user-img" :src="headImgBase64"/>
        </span>
          <el-dropdown-menu slot="dropdown" style="margin-bottom:0;padding: 0;">
            <el-dropdown-item
              command="SELF_CONF"
              class="joys-admin-header__user-item"
            >
              <i class="joys-icon-account"/>
              <span class="joys-admin-header__user-item-text">账户信息</span>
            </el-dropdown-item>
            <el-dropdown-item
              command="SELF_SECURE"
              class="joys-admin-header__user-item"
            >
              <i
                class="joys-icon-accountsecurity joys-admin-header__user-item-icon"
              />
              <span class="joys-admin-header__user-item-text">账户安全</span>
            </el-dropdown-item>
            <el-dropdown-item command="THEME" class="joys-admin-header__user-item">
              <i class="joys-icon-split joys-admin-header__user-item-icon"/>
              <span class="joys-admin-header__user-item-text">主题切换</span>
            </el-dropdown-item>
            <el-dropdown-item command="EXIT" class="joys-admin-header__user-item">
              <i class="joys-icon-logout joys-admin-header__user-item-icon"/>
              <span class="joys-admin-header__user-item-text">登出</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-col>
  </el-row>
</template>

<script>
  import {mapState, mapActions} from "vuex";
  import bus from "../../assets/Bus.js";
  import FrameAside from "./../aside";

  export default {
    name: "Head",
    components: {
      FrameAside
    },
    data() {
      return {
        mask: true,
        num: 2,
        logo: null,
        headImgBase64: null
      };
    },
    mounted() {
      this.logoFileUrl()
      this.userImg()
    },
    methods: {
      ...mapActions(["openApplet"]),
      message() {
        this.openApplet({appletId: "sys-message"});
      },
      onUserCommand(cmd) {
        if (cmd == "SELF_CONF") {
          this.openApplet({appletId: "self-config"});
        } else if (cmd == "SELF_SECURE") {
          this.openApplet({appletId: "secure-config"});
        } else if (cmd == "EXIT") {
          bus.$emit("quit", this.mask);
        } else if (cmd == "THEME") {
          bus.$emit("theme", this.mask);
        }
      },
      menuEvent() {
        this.$emit('childMouseover')
      },
      menuEventHide() {

        this.$emit('childMouseoverHide')
      },
      logoFileUrl() {
        this.$http.get('/joys-rest/joys-master-data/tenant/logo/logo').then(resp => {
          this.logo = resp.body
        }).catch(error => {
          this.$message.error('加载失败')
        })
      },
      userImg() {
        if (this.user.userId) {
          this.headImgBase64 = require("../../assets/head0.jpg")
          this.$http.get('/joys-rest/joys-master-data/users/head/' + this.user.userId).then(resp => {
            if (resp.body&&resp.bodyText != '') {
              this.headImgBase64 = resp.body
            }
          }).catch(error => {
            this.$message.error('加载失败')
          })
        }
      }
    },
    computed: {
      ...mapState(["user", "paths", "activeIndex", 'tenant']),

    },
    watch:{
      user(){
        this.userImg()
      }
    }
  };
</script>
<style>
  .joys-admin-header {
    display: flex;
    justify-content: space-between;
    height: 48px;
  }

  .joys-admin-header__left-bar {
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }

  .menuImg_box_top {
    height: 5px;
    width: 100px;
    float: left;
    position: absolute;
    top: 0px;
  }
  .menuImg_box_right{
    height: 48px;
    width: 50px;;
  }

  .menuImg_box {
    float: left;
    height: 48px;
    /*width: 23px;*/
    line-height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: pointer;
  }

  .joys-admin-header__right-bar {
    padding: 0 8px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    width: 100%;
    margin-top: 10px;
    cursor: pointer;
  }

  .joys-admin-header__right-bar .joys-icon-notice {
    color: #d62f17;
    font-size: 16px;
  }

  .joys-admin-header__user {
    display: flex;
    align-items: center;
  }

  .joys-admin-header__user-text {
    display: inline-block;
    height: 32px;
    line-height: 32px;
    padding: 0 15px;
  }

  .joys-admin-header__user-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #ccc;
    overflow: hidden;
  }

  .joys-admin-header__user-item.el-dropdown-menu__item {
    width: 180px;
    height: 48px;
    line-height: 48px;
    padding-left: 24px;
    border-top: #f2f2f2 solid 1px;
  }

  .joys-admin-header__user-item.el-dropdown-menu__item:not(.is-disabled):hover,
  .joys-admin-header__user-item.el-dropdown-menu__item:focus {
    background-color: #f2f2f2;
  }

  .joys-admin-header__user-item:first-child {
    border-top: none;
  }

  .joys-admin-header__user-item-icon {
    font-size: 12px;
  }

  .joys-admin-header__user-item-text {
    margin-left: 18px;
  }

</style>
